const int filterItemTypeOther = 0;
const int filterItemTypeNone = 1;
const int filterItemTypeOne = 2;
const int filterItemTypeTwo = 3;
const int filterItemTypeFilter = 4;
const int filterItemTypeTime = 5;

class FilterItemData {
  FilterItemData(this.name,
      {this.code,
      this.value,
      this.select = 0,
      this.children,
      this.type = 0,
      this.radio = false,
      this.open = false});

  late String name;
  late String? code;
  late String? value;

  /*0未选中 1选中 2次要选中*/
  int select;
  List<FilterItemData>? children;
  int type;
  bool radio;
  bool open;

  bool isSelect() => select != 0;

  void setSelect(bool select) => this.select = select ? 1 : 0;

  void updateSelect() => select = (select == 1 ? 2 : 1);

  factory FilterItemData.fromJson(Map<String, dynamic> json) => FilterItemData(
        json['name'] as String,
      )
        ..code = json['code'] as String?
        ..value = json['value'] as String?
        ..select = (json['select'] ?? 0) as int
        ..children = (json['children'] as List<dynamic>?)
            ?.map((e) => FilterItemData.fromJson(e as Map<String, dynamic>))
            .toList()
        ..type = json['type'] as int
        ..radio = (json['radio'] ?? false) as bool
        ..open = (json['open'] ?? false) as bool;

  Map<String, dynamic> toJson() => <String, dynamic>{
        'name': name,
        'code': code,
        'value': value,
        'select': select,
        'children': children?.map((e) => e.toJson()).toList(),
        'type': type,
        'radio': radio,
        'open': open,
      };
}
